package h0801;

import java.util.*;

/**
  * @description 字符串排序
  * @author 不知名帅哥
  * @date 2024/8/1 23:20
  * @version 1.0
*/
public class SortString {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String[] s = sc.nextLine().split(" ");
        //先去重，再排序
        List<String> words=new ArrayList<>();
        List<String> tmp=new ArrayList<>();
        for (int i = 0; i < s.length; i++) {
            String origin=s[i];
            String temp = s[i].toLowerCase();
            if (!tmp.contains(temp)){
                words.add(origin);
                tmp.add(temp);
            }
        }
        String res=sortWords(words);
        System.out.println(res);
    }

    private static String sortWords(List<String> words) {
        words.sort((o1, o2) -> {
            int lim=Math.min(o1.length(),o2.length());
            for (int i = 0; i < lim; i++) {
                char a = Character.toLowerCase(o1.charAt(i));
                char b = Character.toLowerCase(o2.charAt(i));
                if (a!=b){
                    return a-b;
                }
            }
            //前缀都一样，哪个短哪个先输出。
           return o1.length()-o2.length();
        });
        StringJoiner joiner = new StringJoiner(" ");
        for (String word : words) {
            joiner.add(word);
        }
        return joiner.toString();
    }
}
